package com.bajiao.common.api.vo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * 封装IPage分页对象
 */
@Data
@ApiModel("PageQO")
public class PageQO<T> {
    private static final long versionUID = 8546547890325528733L;
    //数据
    @ApiModelProperty(value = "数据")
    private List<T> data;
    //总共多少条数据
    @ApiModelProperty(value = "总共多少条数据")
    private long total;
    //一页多少条数据
    @ApiModelProperty(value = "一页多少条数据")
    private long pre_page;
    //总共多少页
    @ApiModelProperty(value = "总共多少页")
    private long last_page;
    //当前是第几页
    @ApiModelProperty(value = "当前是第几页")
    private long current_page;

    /**
     * 组装前端分页所需数据
     * @param iPage
     * @return
     */
    public static PageQO paginationIPage(IPage<?> iPage){
        PageQO pageQO = new PageQO();
        pageQO.setData(iPage.getRecords());
        pageQO.setTotal(iPage.getTotal());
        pageQO.setPre_page(iPage.getSize());
        pageQO.setLast_page(iPage.getPages());
        pageQO.setCurrent_page(iPage.getCurrent());
        return  pageQO;
    }

}
